%
% 
function [x5 u5] = sNuN()
% % % % payoff_matrix=[0 3 4 11 11;5 0 2 11 12;2 5 0 9 12;6 10 10 0 3;10 10 10 4 0];
% % % %  f_head = 'D:\fromWZJ2018\WZJ2018DeskF\书洁芹梅\yqm代码+数据\5_s_exp5策略实验数据\ezp';
% % % %  ezp={'01205A551','01206A552','01206A553', '01229A554','01230A555',  '01230A556'};
% % % % outfile = 'Y5o_ezp_s5u5.csv'

% % % %  payoff_matrix=[0 0 0 4; 1 0 0 0; 0 1 0 0; 0 0 1 0];
% % % %  f_head = 'D:\fromWZJ2018\WZJ2018DeskF\书洁芹梅\周书洁数据以及代码整理\实验数据集合zsj\原始数据\A44\ezp';
% % % %  ezp= {'01122A441','01122A442','01128A443','01128A444','01129A445','01129A446','01219A448','01228A449'};
% % % %  outfile = 'A444_ezp_s4u4.csv';  
 
% % % %  payoff_matrix=[0 0 0 1/4; 1 0 0 0; 0 1 0 0; 0 0 1 0];
% % % %  f_head = 'D:\fromWZJ2018\WZJ2018DeskF\书洁芹梅\周书洁数据以及代码整理\实验数据集合zsj\原始数据\A25\ezp';
% % % %  ezp= {'01121A251','01121A252','01122A253','01122A254','01128A255','01129A256','01219A258','01227A250'};
% % % %  outfile = 'A425_ezp_s4u4.csv';  
 
 
s=[]; 
for EID = 1:size(ezp,2)  %totalsession
   string(ezp(EID))
    csvfile=strcat(f_head,  string(ezp(EID)),'.csv');
    data = readtable(csvfile, 'Range', 'A1:Z6900');
    dat1=sortrows(data,[5,8,9]);

    for i=1:6:6000; 
        t=table2array(dat1(i:i+5,12)); 
        [s5 u5] = sNuN2(payoff_matrix,t)  ; 
        s = [s; s5 u5]; 
    end 
end 
    csvwrite(outfile,s)
end


function [x5 u5] = sNuN2(A, s)
s=s+1; % 0,1,2,3,4 

    L =size(A,1);
    x5 = zeros(1,L);
    u5 = zeros(1,L);
    
    u=[];
    for j=1:2:size(s,1)
        u(j) =A(s(j), s(j+1));
        u(j+1) =A(s(j+1), s(j));
    end
    
    for k=1:L
        B = find(s==k);
        x5(k) = size(B,1); 
        if size(B,1) > 0
            u5(k) = mean(u(B(:,1)));
        end
    end

end